{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 1. range函数使用"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "range(0, 10)\n",
      "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n",
      "[1, 2, 3, 4, 5, 6, 7, 8, 9]\n",
      "[1, 3, 5, 7, 9]\n",
      "False\n",
      "True\n",
      "True\n",
      "range(1, 20)\n",
      "range(1, 101)\n"
     ]
    }
   ],
   "source": [
    "# range()的三种使用方式\n",
    "# 第一种：只有一个参数，括号中只有一个值，默认从0开始，默认相差1为步长\n",
    "r = range(10)\n",
    "print(r)  # range(0,10)\n",
    "print(list(r))  # 用于查看range对象中的整数序列  -->list是列表的意思\n",
    "\n",
    "# 第二种：两个参数，表示开始和结尾，默认步长为1\n",
    "rr = range(1, 10)\n",
    "print(list(rr))\n",
    "\n",
    "# 第三种，三个参数，表示开始、结尾和步长\n",
    "rrr = range(1, 10, 2)\n",
    "print(list(rrr))\n",
    "\n",
    "# 使用in与not in判断整数序列中是否存在指定的整数\n",
    "print(10 in rrr)\n",
    "print(9 in rrr)\n",
    "print(10 not in rrr)\n",
    "\n",
    "# 好处：只存储对应的参数，内存空间相同\n",
    "print(range(1, 20, 1))  # [1...19]\n",
    "print(range(1, 101, 1))  # [1...100]\n",
    "# 只有在用到range对象时，才计算序列中的相关元素"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.6.3",
   "language": "python",
   "name": "python3.6.3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": false,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
